Computer processors execute multiple tasks very quickly by dividing execution cycles between different threads of executable code. This is often called multithreading. In addition, hyperthreaded processor cores may have extra circuitry to emulate multiple processors by having extra sets of registers but using the execution units of a single processor. Recently, multiple core processors have been introduced that have entire processors co-located on the same silicon integrated circuit. These approaches may also be combined in a multi-core processor where each core is hyperthreaded.
To multithread, a processor undergoes a context switch. One example context is a processor state including the contents of registers and a program counter. A context switch involves halting the progression of a first process and storing the context for that process in memory. Then, the processor retrieves a context of a second process from memory, loads it in the registers, and loads the memory address in the program counter corresponding to the second process.
Example context switches include user level to system level switches, often called system calls, context switches between virtual machines, and context switches due to interrupt service routines. Although context switches allow a processor to schedule multiple threads, a portion of the processing budget must be dedicated to saving and loading the processor state. Hardware costs for system call context switches may be hundreds of processor cycles, for virtual machine context switches thousands of cycles, and for interrupt context switches (exceptions), hundreds to a few thousand cycles. Software costs for a context switch also depend on the type of context switch and may also be non-trivial.